//
//  GMExerciseNotesCell.m
//  Teecloud
//
//  Created by 小熊 on 2018/11/27.
//  Copyright © 2018年 小志. All rights reserved.
//

#import "GMExerciseNotesCell.h"
#import "GMResultCell.h"
@interface GMExerciseNotesCell()<UICollectionViewDataSource,UICollectionViewDelegate,XMGWaterflowLayoutDelegate>
@property (weak, nonatomic) IBOutlet UILabel *timeLab;
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *collectionViewHight;

@property (weak, nonatomic) IBOutlet UILabel *labq;
@property (weak, nonatomic) IBOutlet UILabel *labw;
@property (weak, nonatomic) IBOutlet UILabel *labe;
@property (nonatomic, strong) NSMutableArray *dataArr;

@end
@implementation GMExerciseNotesCell

- (void)awakeFromNib {
    [super awakeFromNib];
    XMGWaterflowLayout *layout = [[XMGWaterflowLayout alloc] init];
    layout.delegate = self;
    self.collectionView.collectionViewLayout =layout;
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    [self.collectionView registerNib:[UINib nibWithNibName:@"GMResultCell" bundle:nil] forCellWithReuseIdentifier:@"GMResultCell"];
}
-(void)setModel:(GMExamModel *)model{
    _model = model;
    self.timeLab.text = model.Title;
    self.labq.text = model.CorrectRate;
    self.labw.text = [NSString stringWithFormat:@"%ld",model.UseTime];
    self.labe.text = model.AverageTime;
    self.collectionViewHight.constant =40 *(model.AnswerCards.count +5 -1)/5;
    model.cellHight = self.collectionViewHight.constant + 110;
    [self.dataArr removeAllObjects];
    [self.dataArr addObjectsFromArray:model.AnswerCards];
    [self.collectionView reloadData];
}
-(NSMutableArray *)dataArr{
    if (!_dataArr) {
        _dataArr = [[NSMutableArray alloc] init];
    }
    return _dataArr;
}
//每个section的item个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.dataArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    GMResultCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"GMResultCell" forIndexPath:indexPath];
    GMAnswerCards *model = self.dataArr[indexPath.row];
    cell.model = model;
    return cell;
}
#pragma mark - <XMGWaterflowLayoutDelegate>
- (CGFloat)waterflowLayout:(XMGWaterflowLayout *)waterflowLayout heightForItemAtIndex:(NSUInteger)index itemWidth:(CGFloat)itemWidth{
    //计算item的高度
    return itemWidth;
}
/**行间距*/
- (CGFloat)rowMarginInWaterflowLayout:(XMGWaterflowLayout *)waterflowLayout{
    return 10;
}
/**列间距*/
-(CGFloat)columnMarginInWaterflowLayout:(XMGWaterflowLayout *)waterflowLayout{
    return 10;
}
/**返回每行的个数*/
- (CGFloat)columnCountInWaterflowLayout:(XMGWaterflowLayout *)waterflowLayout{
    return 5;
}
- (UIEdgeInsets)edgeInsetsInWaterflowLayout:(XMGWaterflowLayout *)waterflowLayout{
    return UIEdgeInsetsMake(10, 10, 10, 10);
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    self.itemBlock(indexPath.row);
}
@end
